﻿using AbstractFactoryPattern.SkinBank;
using System;
using System.Configuration;
using System.Reflection;

namespace AbstractFactoryPattern
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello AbstractFactoryPattern!");

            {
                //xml配置文件与反射方式扩展
                // 1.读取【App.config】配置文件
                string factoryString = ConfigurationManager.AppSettings["spring"];
                ISkinFactory skinFactory = (ISkinFactory)Assembly.Load("AbstractFactoryPattern").CreateInstance(factoryString);
                IButton ibtn = skinFactory.CreateButton();
                IComboBox iComBox = skinFactory.CreateComboBox();
                ITextFiled iTextFiled = skinFactory.CreateTextFiled();

                ibtn.Display();
                iComBox.Display();
                iTextFiled.Display();
            }

            Console.ReadKey();
        }
    }

    #region AbstractFactory-Demo
    /// <summary>
    /// 抽象工厂
    /// </summary>
    abstract class AbstractFactory
    {
        //工厂方法A
        public abstract AbstractProduceA CreateProduceA();
        //工厂方法B
        public abstract AbstractProduceB CreateProduceB();
    }

    /// <summary>
    /// 具体工厂1
    /// </summary>
    class ConcreteFactory1 : AbstractFactory
    {
        public override AbstractProduceA CreateProduceA()
        {
            return new AbstractProduceA();
        }

        public override AbstractProduceB CreateProduceB()
        {
            return new AbstractProduceB();
        }
    }

    class AbstractProduceA
    {

    }

    class AbstractProduceB
    {

    }
    #endregion

}
